namespace('n2.simulate');

n2.simulate = function() {
	this._drag = null;
	// this.abc = "abc";
	//	this.a = null;
	//	this.b = null
	n2.base(this, n2.simulate);
};
n2.definePrototype(n2.simulate.prototype, {
	_drag: {
		set: function(value) {
			this.drag = value;
		},
		get: function() {
			return this.drag;
		}
	}
});

var drag = function(parent, child) {
	var parent = document.querySelector(parent);
	var childs = document.querySelectorAll(child);
	parent.addEventListener("touchstart", function(e) {
		console.log(e);
		var touches = e.touches[0];
		oW = touches.clientX - parent.offsetLeft;
		oH = touches.clientY - parent.offsetTop;
		//阻止页面的滑动默认事件
		document.addEventListener("touchmove", defaultEvent, false);
	}, false)

	parent.addEventListener("touchmove", function(e) {
		var touches = e.touches[0];
		var oLeft = touches.clientX - oW;
		var oTop = touches.clientY - oH;
		if(oLeft < 0) {
			oLeft = 0;
		} else if(oLeft > document.documentElement.clientWidth - block.offsetWidth) {
			oLeft = (document.documentElement.clientWidth - block.offsetWidth);
		}
		parent.style.left = oLeft + "px";
		parent.style.top = oTop + "px";
	}, false);

	parent.addEventListener("touchend", function() {
		document.removeEventListener("touchmove", defaultEvent, false);
	}, false);

	function defaultEvent(e) {
		e.preventDefault();
	}
}
//drag('#tucenglist','.tucenginfo');

function adaptive() {
	// Get your own Bing Maps API key at https://www.bingmapsportal.com, prior to publishing your Cesium application:
	Cesium.BingMapsApi.defaultKey = 'put your API key here';
	// Construct the default list of terrain sources.
	var terrainModels = Cesium.createDefaultTerrainProviderViewModels();
	// Construct the viewer with just what we need for this base application
	var viewer = new Cesium.Viewer('cesiumContainer', { //前一个字符串对应ID
		timeline: false, //不会创建timeline小窗口
		animation: false, //不创建动画小部件
		vrButton: true,
		sceneModePicker: false,
		infoBox: true,
		baseLayerPicker: false, //不创建选取地图小部件
		scene3DOnly: true,
		terrainProviderViewModels: terrainModels,
		selectedTerrainProviderViewModel: terrainModels[1], // Select STK high-res terrain
		//添加图像层，此时baseLayerPicker设为false
		imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
			url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
		})

	});
	// No depth testing against the terrain to avoid z-fighting
	viewer.scene.globe.depthTestAgainstTerrain = false;
	// Add credit to Bentley
	// Bounding sphere
	var boundingSphere = new Cesium.BoundingSphere(Cesium.Cartesian3.fromDegrees(6.681247027, 46.55189101, 871.5000123), 493.3407689);
	// Override behavior of home button
	viewer.homeButton.viewModel.command.beforeExecute.addEventListener(function(commandInfo) {
		// Fly to custom position
		viewer.camera.flyToBoundingSphere(boundingSphere);
		// Tell the home button not to do anything
		commandInfo.cancel = true;
	});
	// Set custom initial position
	viewer.camera.flyToBoundingSphere(boundingSphere, {
		duration: 0
	});
	/*---------------------------------------------------------------------------------**/
	/**
	* @bsimethod
	+---------------+---------------+---------------+---------------+---------------+------*/
	// Functions to adapt screen space error and memory use to the device
	var isMobile = {
		Android: function() {
			return navigator.userAgent.match(/Android/i);
		},
		BlackBerry: function() {
			return navigator.userAgent.match(/BlackBerry/i);
		},
		iOS: function() {
			return navigator.userAgent.match(/iPhone|iPad|iPod/i);
		},
		Opera: function() {
			return navigator.userAgent.match(/Opera Mini/i);
		},
		Windows: function() {
			return navigator.userAgent.match(/IEMobile/i);
		},
		any: function() {
			return(isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
		}
	};
	// Add tileset. Do not forget to reduce the default screen space error to 1
	var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
		url: '../Scene/Production_4.json',
		maximumScreenSpaceError: isMobile.any() ? 8 : 1, // Temporary workaround for low memory mobile devices - Increase maximum error to 8.
		maximumNumberOfLoadedTiles: isMobile.any() ? 10 : 1000 // Temporary workaround for low memory mobile devices - Decrease (disable) tile cache.

	}));
	// Create buttons
	Sandcastle.addToolbarButton('显示三维地图', function() {
		tileset.show = !tileset.show;
	});
	Sandcastle.addToolbarButton('显示标注', function() {
		var len;
		for(var index = 0, len = POIs.length; index < len; ++index) {
			POIs[index].show = !(POIs[index].show);
		}
	});
	Sandcastle.addToolbarButton('显示区域', function() {
		districts.show = !districts.show;
	});
	Sandcastle.addToolbarButton('显示自行车道', function() {
		bikeLanes.show = !bikeLanes.show;
	});
}